package com.guanjia.service.impl;

import com.guanjia.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: jzhang
 * @Date: 2018/10/15 15:51
 * @Description:    自定义用户登录
 */
@Service
public class UserLoginService implements UserDetailsService { //自定义UserDetailsService 接口

    @Autowired
    private UserMapper userMapper;

    public UserDetails loadUserByUsername(String tell) {


        com.guanjia.entity.User user=userMapper.findUserBytell(tell);
        List<GrantedAuthority> authorities=new ArrayList<>();
        GrantedAuthority grantedAuthority=new SimpleGrantedAuthority("普通用户");
        authorities.add(grantedAuthority);

       return new User(user.getTell(),user.getPassword(),authorities);
    }

}
